package cn.shujuhai.qtadmin.platform.controller;

import java.util.Map;

import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

import cn.hutool.core.text.CharSequenceUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * PageController
 *
 * @author dch798
 * @date 2021/09/29 21:38
 **/
@Slf4j
@Controller
public class PageController {

    /**
     *
     * @param folder
     *            文件夹
     * @param page
     *            页面
     * @return 视图
     */
    @GetMapping(value = {"/", "/{page}", "/{folder:^(?!swagger-ui).*$}/{page}"})
    public String showPage(@PathVariable(value = "folder", required = false) String folder,
        @PathVariable(value = "page", required = false) String page,
        @RequestParam(required = false) Map<String, String> parms, @NotNull ModelMap result) {
        result.mergeAttributes(parms);
        page = CharSequenceUtil.isNotBlank(folder) ? folder + "/" + page : page;
        page = CharSequenceUtil.isNotBlank(page) ? page : "/";
        log.info("get page:" + page);
        return page;
    }
}
